package com.cloudfun.campusshare.controller;

import com.cloudfun.campusshare.common.constant.RoleType;
import com.cloudfun.campusshare.common.model.dto.MerchantDto;
import com.cloudfun.campusshare.common.model.vo.AuthOrgVO;
import com.cloudfun.campusshare.common.model.vo.MerchantAuditVo;
import com.cloudfun.campusshare.common.model.vo.MerchantVo;
import com.cloudfun.campusshare.common.model.vo.ReviewOverviewVo;
import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.response.BaseResultFactory;
import com.cloudfun.campusshare.common.response.PageResult;
import com.cloudfun.campusshare.common.security.AuthRequired;
import com.cloudfun.campusshare.entity.AuthOrgEntity;
import com.cloudfun.campusshare.service.AuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * @Author : linyangping
 * @Date : Created in 5:06 PM 2019/11/19
 */
@RestController
@RequestMapping("/v1/auth")
@Api(value = "认证模块", description = "认证模块", position = 9)
public class AuthController {

    @Autowired
    private AuthService authService;


    @ApiOperation(value = "企业认证", notes = "企业认证")
    @RequestMapping(value = "/org", method = RequestMethod.POST)
    @AuthRequired(role = {RoleType.OPERATIONAL_MERCHANT})
    BaseResult<?> authOrg(@Valid @RequestBody AuthOrgVO authOrgVO) {

        return authService.authOrg(authOrgVO);
    }

    @ApiOperation(value = "企业认证信息修改", notes = "企业认证信息修改")
    @RequestMapping(value = "/org", method = RequestMethod.PUT)
    @AuthRequired(role = {RoleType.OPERATIONAL_MERCHANT})
    BaseResult<?> authInfo(@Valid @RequestBody AuthOrgVO authOrgVO) {
        return authService.authOrg(authOrgVO);
    }

    @ApiOperation(value = "运营商提交资料去平台审核", notes = "运营商提交资料去平台审核")
    @RequestMapping(value = "operational/submit", method = RequestMethod.PUT)
    @AuthRequired(role = {RoleType.OPERATIONAL_MERCHANT})
    BaseResult<?> operationalAudit() {
        return authService.operationalAudit();
    }

    @ApiOperation(value = "获取认证信息", notes = "获取认证信息")
    @RequestMapping(value = "", method = RequestMethod.GET)
    @AuthRequired
    BaseResult<?> authInfo() {
        return authService.authInfo();
    }

    @ApiOperation(value = "获取认证信息", notes = "获取认证信息")
    @RequestMapping(value = "get/{userId}", method = RequestMethod.GET)
    @AuthRequired(role = {RoleType.ADMIN,RoleType.OPERATIONAL_MERCHANT})
    BaseResult<AuthOrgEntity> get(@PathVariable String userId) {
        return authService.get(userId);
    }

    @ApiOperation(value = "认证审核", notes = "认证审核")
    @RequestMapping(value = "/audit", method = RequestMethod.PUT)
    @AuthRequired(role = {RoleType.ADMIN})
    BaseResult<?> authAudit(@Valid @RequestBody MerchantAuditVo auditVo) {
        return authService.authAudit(auditVo);
    }

    @ApiOperation(value = "审核列表获取", notes = "审核列表获取")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @AuthRequired(role = {RoleType.ADMIN})
    BaseResult<PageResult<MerchantVo>> list(@ApiParam(value = "merchantDto") MerchantDto merchantDto) {
        return BaseResultFactory.produceSuccess(authService.findAll(merchantDto));
    }


    @ApiOperation(value = "审核概况统计", notes = "审核概况统计")
    @RequestMapping(value = "/reviewOverview", method = RequestMethod.GET)
    @AuthRequired(role = {RoleType.ADMIN})
    BaseResult<ReviewOverviewVo> reviewOverview() {
        return BaseResultFactory.produceSuccess(authService.reviewOverview());
    }


}
